package com.qdlc.p2p.biz.model;

import java.util.HashMap;
import java.util.Map;

import com.qdlc.p2p.biz.service.UserService;
import com.qdlc.p2p.common.exception.UserException;
import com.qdlc.p2p.common.util.BeanUtil;
import com.qdlc.p2p.common.util.PropertiesUtil;
import com.qdlc.p2p.common.util.StringUtil;
import com.qdlc.p2p.dal.dto.User;

public class AppGetPwdModel {
	
	/**找回密码凭证，可以是手机号或者邮箱*/
	private String receiveAddr;
	
	/**以何种方式找回密码*/
	private String type;
	
	/**验证码类型*/
	private String noticeId;
	
	/**密码类型---登录密码，支付密码*/
	private String pwdType;
	
	
	/**新密码*/
	private String newPwd;
	
	/**确认密码*/
	private String confPwd;// 	String	N		
	
	/**用户名*/
	private String userName;

	private Map<String,Object> data;
	
	
	/**
	 * 找回密码响应信息
	 * @return
	 */
	public Map<String,Object> getpwdResponse(User user){
		data = new HashMap<String,Object>();
		UserService userService = (UserService)BeanUtil.getBean("userService");
		if(StringUtil.equals("payPwd", getPwdType())){	//设置新的支付密码
			user.setPayPwd(getNewPwd());
			user.setUserId(user.getUserId());
			userService.modifyPaypwd(user);
		}
		if(StringUtil.equals("userPwd", getPwdType())){ //设置新的用户密码
			user.setPwd(getNewPwd());
			user.setUserId(user.getUserId());
			userService.modifyPwd(user);
		}
		data.put("resCode", "1");
		data.put("userName", user.getUserName());
		return data;
	}
	
	/**
	 * 找回密码(发送验证码)  参数校验
	 * @return
	 */
	public Map<String,Object> validParam(){
		data = new HashMap<String,Object>();
		if(StringUtil.isBlank(getReceiveAddr())){
			data.put("resCode", "0");
			data.put("resMsg", PropertiesUtil.getValue("FindPassWord01"));
			return data;
		}
		if(StringUtil.isBlank(getType())){
			data.put("resCode", "0");
			data.put("resMsg", PropertiesUtil.getValue("FindPassWord02"));
			return data;
		}
		if(StringUtil.isBlank(getNoticeId())){
			data.put("resCode", "0");
			data.put("resMsg", PropertiesUtil.getValue("FindPassWord06"));
			return data;
		}
		
		return null;
	}
	
	

	public String getReceiveAddr() {
		return receiveAddr;
	}
	public void setReceiveAddr(String receiveAddr) {
		this.receiveAddr = receiveAddr;
	}
	/**
	 * 找回密码(设置新密码) 参数校验
	 * @return
	 */
	public Map<String,Object> validParams(){
		data = new HashMap<String,Object>();
		if(StringUtil.isBlank(getReceiveAddr())){
			data.put("resCode", "0");
			data.put("resMsg", PropertiesUtil.getValue("FindPassWord01"));
			return data;
		}
		if(StringUtil.isBlank(getType())){
			data.put("resCode", "0");
			data.put("resMsg", PropertiesUtil.getValue("FindPassWord02"));
			return data;
		}
		if(StringUtil.isBlank(getNewPwd())){
			data.put("resCode", "0");
			data.put("resMsg", PropertiesUtil.getValue("FindPassWord05"));
			return data;
		}
		if(StringUtil.isBlank(getConfPwd())){
			data.put("resCode", "0");
			data.put("resMsg", PropertiesUtil.getValue("FindPassWord04"));
			return data;
		}
		if(StringUtil.isBlank(getPwdType())){
			data.put("resCode", "0");
			data.put("resMsg", PropertiesUtil.getValue("FindPassWord06"));
			return data;
		}
		return null;
	}
	
	public void validUser(User user){
		if(StringUtil.isBlank(user)){
			throw new UserException("用户不存在", 0);
		}
	}


	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPwdType() {
		return pwdType;
	}
	
	public void setPwdType(String pwdType) {
		this.pwdType = pwdType;
	}

	public String getNewPwd() {
		return newPwd;
	}

	public void setNewPwd(String newPwd) {
		this.newPwd = newPwd;
	}

	public String getConfPwd() {
		return confPwd;
	}

	public void setConfPwd(String confPwd) {
		this.confPwd = confPwd;
	}

	public Map<String, Object> getData() {
		return data;
	}

	public void setData(Map<String, Object> data) {
		this.data = data;
	}
	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	public String getNoticeId() {
		return noticeId;
	}
	public void setNoticeId(String noticeId) {
		this.noticeId = noticeId;
	}
	
}
